# @Author: dpf
# @Date  : 2024/11/28/15:20
from entity.UserModel import User
from util import dbUtil

# 当前登录用户
currentUser: User = None


def login(user: User):
    con = None
    try:
        con = dbUtil.getCon()
        cursor = con.cursor()
        cursor.execute(f"select * from admin_user where logName = '{user.logName}' and password = '{user.password}' ")
        return cursor.fetchone()
    except Exception as e:
        print(e)
        con.rollback()
        return None
    finally:
        dbUtil.closeCon(con)


def modifyPassword(user: User):
    con = None
    try:
        con = dbUtil.getCon()
        cursor = con.cursor()
        cursor.execute(f"update  admin_user set password='{user.password}' where logName = '{user.logName}'")
        return cursor.rowcount
    except Exception as e:
        print(e)
        con.rollback()
        return 0
    finally:
        dbUtil.closeCon(con)
